package com.cdfahe.common.util.mail;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 邮件实体类
 * @author  Karl
 * @version 
 * @since   JDK1.6
 */
public class Mail {
	/**
	 * 服务器smtp协议地址
	 * eg:smtp.qq.com
	 */
	private String host;
	/**
	 * 服务器smtp协议端口
	 * eg:25，465等
	 */
	private String port;
	/**
	 * 服务器发信人帐号
	 */
	private String username;
	/**
	 * 服务器发信人密码
	 */
	private String password;
	/**
	 * 
	 */
	private String from;
	/**
	 * 服务器发信人名称
	 * eg：成都法和药业有限责任公司
	 */
	private String fromname;
	/**
	 * 点击回复时候，回复信息的地址
	 */
	private List<String> replyto;
	/**
	 * 收件人
	 */
	private List<String> to;
	/**
	 * 
	 */
	private List<String> cc;
	/**
	 * 抄送人地址
	 */
	private List<String> bcc;
	/**
	 * 邮件主题
	 */
	private String subject;
	/**
	 * 邮件内容
	 */
	private String content;
	/**
	 * 是否使用SSL
	 */
	private boolean isUseSSL;
	/**
	 * 标识是否附带附件
	 */
	private boolean isAttached = false;
	/**
	 * 附件MAP，key为附件在邮件的显示名称，value为附件对应的uri地址
	 */
	private Map<String, String> attached;
	
	public Mail() {
	}
	
	public Mail(String host,String port, String username, String password, String from) {
		this.host = host;
		this.username = username;
		this.password = password;
		this.from = from;
		this.port = port;
	}
	
	public Mail(String host, String username, String password, String from) {
		this.host = host;
		this.username = username;
		this.password = password;
		this.from = from;
	}

	public String getHost() {
		return host;
	}

	public void setHost(String server) {
		this.host = server;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getFrom() {
		return from;
	}

	public void setFrom(String from) {
		this.from = from;
	}

	public List<String> getTo() {
		return to;
	}

	public void initializeTo(List<String> to) {
		this.to = to;
	}

	public void addTo(String to) {
		if (getTo() == null) {
			this.to = new ArrayList<String>();
		}
		getTo().add(to);
	}

	public void removeTo(String to) {
		if (getTo() != null && getTo().contains(to))
			getTo().remove(to);
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public String getPort() {
		return port;
	}

	public void setPort(String port) {
		this.port = port;
	}

	public List<String> getCc() {
		return cc;
	}

	public void initializeCc(List<String> cc) {
		this.cc = cc;
	}

	public void addCc(String cc) {
		if (getCc() == null) {
			this.cc = new ArrayList<String>();
		}
		getCc().add(cc);
	}

	public void removeCc(String cc) {
		if (getCc() != null && getCc().contains(cc))
			getCc().remove(cc);
	}

	public List<String> getBcc() {
		return bcc;
	}

	public void initializeBcc(List<String> bcc) {
		this.bcc = bcc;
	}

	public void addBcc(String bcc) {
		if (getBcc() == null)
			this.bcc = new ArrayList<String>();
		getBcc().add(bcc);
	}

	public void removeBcc(String bcc) {
		if (getBcc() != null && getBcc().contains(bcc))
			getBcc().remove(bcc);
	}

	public String getFromname() {
		return fromname;
	}

	public void setFromname(String fromname) {
		this.fromname = fromname;
	}

	public List<String> getReplyto() {
		return replyto;
	}

	public void initializeReplyto(List<String> replyTo) {
		this.replyto = replyTo;
	}

	public void addReplyto(String replyto) {
		if (getReplyto() == null) {
			this.replyto = new ArrayList<String>();
		}
		getReplyto().add(replyto);
	}

	public boolean isUseSSL() {
		return isUseSSL;
	}

	public void setUseSSL(boolean isUseSSL) {
		this.isUseSSL = isUseSSL;
	}

	/**
	 * 是否附加附件
	 * 
	 * @return
	 */
	public boolean isAttached() {
		return isAttached;
	}

	/**
	 * 是否附加附件
	 * 
	 * @param isAttached
	 */
	public void setAttached(boolean isAttached) {
		this.isAttached = isAttached;
	}

	/**
	 * 所需要增加的附件map
	 * 
	 * @return
	 */
	public Map<String, String> getAttached() {
		return attached;
	}

	// 添加附件
	public void addAttached(String fileName, String fileUri) {
		if (fileName == null || fileName.trim().equals("") || fileUri == null || fileUri.trim().equals("")) {
			return;
		}
		if (attached == null) {
			attached = new HashMap<String, String>();
		}
		attached.put(fileName, fileUri);
	}
}
